﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PayloadTracker.APRS.SoundModem.Filters
{
    public class LowPass : IFilter
    {
        double m_RC;
        double m_Alpha;
        double m_PreviousValue;
        public LowPass(float Hertz, int sampleRate)
        {

            //Passive electronic realization from wikipedia
            m_RC = 1.0 / Hertz / (2 * Math.PI);
            m_Alpha = 1 / ((float)sampleRate) / (m_RC + 1 / ((float)sampleRate));
            m_PreviousValue = 0f;
        }

        public override double Process(double sample)
        {
            return (m_PreviousValue = (1 - m_Alpha) * m_PreviousValue + m_Alpha * sample);
        }

        public override void Reset()
        {
            m_PreviousValue = 0;
        }
    }
}
